/*列表执行页面*/

/*开关通用按钮 */
function toggleBtn(domstr,tog) {
	/*获取元素*/
	var Btn=mui(domstr);
	//去掉开关类  并合并多余的空格
	Btn.each(function(index,item){
		var BtnClassname=item.className.replace(/open|close/g,"").replace(/\s+/g," ");
		if(tog==true)//传值开
		item.className=BtnClassname+" open";
		else if(tog==false) //传值关
	    item.className=BtnClassname+" close";
		else //不传切换
		item.className=item.className.indexOf(" close")>-1?BtnClassname+" open":BtnClassname+" close";
	})
}

 /*底部按钮事件*/
mui(".screen-btn")[0].addEventListener("tap",function(){
	//开筛选 /*开覆盖层*/ 	/*开确定按钮*/
	toggleBtn(".select,.p-cover,.select-btn",true);
});

mui(".sort-btn")[0].addEventListener("tap",function(){
	//排序 /*开覆盖层*/ 	/*开确定按钮*/
	toggleBtn(".rank,.p-cover,.select-btn",true);
});

/*筛选框事件点击事件*/
mui("#selectWrap")[0].addEventListener("tap",function(ev){
	var ev=ev||event;
	var target = ev.target||ev.srcElement;
		/*条件筛选*/
		if(target.nodeName.toLowerCase()=="li")
		{
			if(target.parentElement.querySelector(".active")!=null)
			{
				target.parentElement.querySelector(".active").className="";
			}
			target.className="active";
		}
		/*清空和确认按钮*/
		if(target.nodeName.toLowerCase()=="button")
		{
			console.log(target);
			if(target.className.indexOf("clear-btn")>-1)
			{
				mui(".select-content .active,.rank ul .active").each(function(index,item){
					item.className=""
				})
			}
			if(target.className.indexOf("confirm-btn")>-1)
			{
				/*筛选事件 发送ajax*/
				trueAjax();
				toggleBtn(".p-cover,.select,.rank,.select-btn",false);
			}
		}
		/*清空和确认按钮*/
		if(target.className.indexOf("p-cover")>-1)
		{
			toggleBtn(".p-cover,.select,.rank,.select-btn",false);
		}
})
	/*获取筛选框的数据*/
	function getData(){
		var data={};
		mui(".select-item").each(function(index,item){
			var name = item.querySelector(".select-header").getAttribute("data-type");
			if(item.querySelector(".select-content .active")!=null){
				data[name]=parseInt(item.querySelector(".select-content .active").getAttribute("data-wy"));
			}
		})
		if(mui(".rank .active").length>0)
		{
			var name = mui(".rank")[0].getAttribute("data-type");
			data[name]=mui(".rank .active")[0].getAttribute("data-wy");
		}
		return data;
	}
	
/*渲染筛选框*/
function drawFilter(url)
{
	/*筛选*/
	mui.ajax(url,{
			dataType:'json',//服务器返回json格式数据
			type:'post',//HTTP请求类型
			timeout:10000,//超时时间设置为10秒；
			headers:{'Content-Type':'application/json'},	              
			success:function(data){
				console.log(data);
	   			var html = template("selectJs",data);
				mui("#selectWrap")[0].innerHTML = html;
			},
			error:function(xhr,type,errorThrown){
				//异常处理；
				console.log(type);
			}
	})
}


